import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import nodejs from '@feidao/web/atom/browser/msg/nodejs';
import render from '@feidao/web/atom/browser/render/render';
import P02 from './P02';
import P04 from './P04';
import P10 from './P10';
import '@feidao/widgets/w-000010';
import Pagination from '@feidao/widgets/w-000010';
import { Handle } from '@feidao/web/node_modules/@feidao/core/on';

// 填充列表数据事件

export default async function (fd: IFeidaoAiBrowserComponent, ...args: any[]) {

	fd.data.list_event.forEach((e: any) => {
		(e[0] as Handle).destroy();
	});
	fd.data.list_event = [];


	const param = {
		criteria: fd.data.criteria,
		page_size: fd.data.page_size,
		page_no: fd.data.page_no,
		asc: fd.data.asc
	};
	const res = await nodejs('flippedclass', 'usable-exam-teacher-find', param);
	console.warn('....................................', res);

	console.log('a004 -----------', res);

	fd.data.res_data = res.dataArray;

	if (res.dataArray.length === 0) {
		fd.data.node.querySelector('[data-feidao-presentation="P02"]').innerHTML = "";
		fd.data.node.querySelector('[data-feidao-presentation="P10"]').innerHTML = "";
		render(fd, res.dataArray, P04, 'P04', "inner");
	} else {
		fd.data.node.querySelector('[data-feidao-presentation="P04"]').innerHTML = "";
		render(fd, res.dataArray, P02, 'P02', "inner");
		const items = document.querySelectorAll<HTMLAnchorElement>('[data-feidao-tno]');
		Array.from(items).forEach((n) => {
			fd.data.list_event.push(fd.parse_event(n));
		});
		render(fd, { count: res.count, page_no: fd.data.page_no }, P10, 'P10', 'inner')
		const widget = document.querySelector<Pagination>('[data-feidao-id="pages"]');
		fd.parse_event(widget);
	}

}